<?php
namespace Home\Controller;
use Think\Controller;
class HycsController extends Controller {
    public function index(){
        cookie('orderid',null);
        cookie('zymd',null);
        cookie('orderidnum','Hycs',604800);
        $imei=cookie('imei');//生成唯一标识imei
        if(empty($imei)){
            $imei=date('Ymd').mt_rand(10000,99999).date('His');
            cookie('imei',$imei,31536000);
        }
        if(!empty($_REQUEST['uid'])){
            cookie('uid',$_REQUEST['uid']);
        }
        $hycscs=S('hycscs');$hycstime=cookie('hycstime');//婚姻测算随机数
        if(empty($hycscs)){$hycscs=mt_rand(200000,399999);S('hycscs',$hycscs);}
        if(empty($hycstime)){$hycscs=S('hycscs')+mt_rand(1,5);S('hycscs',$hycscs);cookie('hycstime',1,1600);}session('hycscs',S('hycscs'));


        $this->display("Hycs/ZM_hunyincesuan");


    }
    public function hycs_zhifu(){
        cookie('orderidnum','Hycs',604800);
        if(cookie('zymd')==''){
            cookie('znickname',I('post.username'),604800);
            cookie('zymd',$_REQUEST['birthday'],604800);
            cookie('zhour',$_REQUEST['hour'],604800);
            cookie('zsex',$_REQUEST['gender'],604800);
        }
        if(!cookie($_REQUEST['username'])){//返回操作
            cookie('znickname',I('post.username'),604800);
            cookie('zymd',$_REQUEST['birthday'],604800);
            cookie('zhour',$_REQUEST['hour'],604800);
            cookie('zsex',$_REQUEST['gender'],604800);
        }
        if(!empty($_REQUEST['ordernum'])){//未支付订单
            $arrdata=M()->query("select * from sm_h5test where ordernum='{$_REQUEST['ordernum']}'");
            $zymd=$arrdata[0]['year'].'-'.str_pad($arrdata[0]['month'],2,"0",STR_PAD_LEFT).'-'.str_pad($arrdata[0]['day'],2,'0',STR_PAD_LEFT);
            cookie('zymd',$zymd,604800);
            cookie('zhour',$arrdata[0]['hour'],604800);
            cookie('znickname',$arrdata[0]['username'],604800);
            cookie('zsex',$arrdata[0]['sex'],604800);

            cookie('orderid',$_REQUEST['ordernum'],604800);
            cookie('orderidnum','Hycs',604800);
        }

        $y=mb_substr(cookie('zymd'),0,4);//年
        $m=mb_substr(cookie('zymd'),5,2); //月
        $d=mb_substr(cookie('zymd'),8,2);//日
        $zyinli=yinli($y,$m,$d);
        cookie('zyangli',$y.'年'.$m.'月'.$d.'日'.' '.cookie('zhour').'时',604800);//阳历
        cookie('zyinli',$zyinli[0].'年'.$zyinli[1].$zyinli[2],604800);//阴历

        $data=cookie('orderid');//获取订单号
        if(empty($data)&&empty($_REQUEST['ordernum'])){
            $orderid='CS'.date('Ymd').mt_rand(100,999).date('His');
            cookie('orderid',$orderid,604800);
        }

        //创建订单
        $hour=cookie('zhour');
        $shop=cookie('orderid');
        $znickname=cookie('znickname');
        $zsex=cookie('zsex');
        $imei=cookie('uid');if(cookie('uid')==''){$imei=cookie('imei');}
        $y=mb_substr(cookie('zymd'),0,4);//年
        $m=mb_substr(cookie('zymd'),5,2); //月
        $d=mb_substr(cookie('zymd'),8,2);//日
        cookie('price',0.01,604800);//价格
        $price=cookie('price');
//        $datastr=stristr(cookie('znickname'),'测试');
//        if($datastr){
//            $price=0.01;
//        }
        if(empty($_REQUEST['ordernum'])){
            $arrdata=M()->query("select * from sm_h5test where ordernum='{$shop}'");
            if(empty($arrdata)){
                M()->query("insert into sm_h5test (ordernum,price,username,typeid,sex,status,datetype,year,month,day,hour,paykind,date_remark,ip)values(
                                              '{$shop}','{$price}','{$znickname}',19,{$zsex},-1,0,{$y},{$m},{$d},{$hour},-1,'{$imei}','{$_SERVER['REMOTE_ADDR']}')");
                M()->query("insert into tb_user_information values(null,'{$shop}','{$_REQUEST['emotion']}','{$_REQUEST['childrens']}','{$_REQUEST['enterprise']}')");
            }
            if(!cookie($_REQUEST['username'])){//返回操作
                //更新订单
                M()->query("update sm_h5test set username='{$znickname}',year={$y},month={$m},day={$d},hour={$hour},sex={$zsex} where ordernum='{$shop}'");
                M()->query("update tb_user_information set emotion='{$_REQUEST['emotion']}',childrens='{$_REQUEST['childrens']}',enterprise='{$_REQUEST['enterprise']}' where orderid='{$shop}'");
            }
        }

        $this->display("Hycs/ZM_hunyincesuan_zhifu");
    }
    public function jieguoye(){
        if(empty($_REQUEST['ordernum'])){
            $y=mb_substr(cookie('zymd'),0,4);//年
            $m=mb_substr(cookie('zymd'),5,2); //月
            $d=mb_substr(cookie('zymd'),8,2);//日
            $zyinli=yinli($y,$m,$d);
            cookie('zyangli',$y.'年'.$m.'月'.$d.'日'.' '.cookie('zhour').'时',604800);//阳历
            cookie('zyinli',$zyinli[0].'年'.$zyinli[1].$zyinli[2],604800);//阴历

            $zymd= cookie('zymd');
        }else{
            $arrdata=M()->query("select * from sm_h5test where ordernum='{$_REQUEST['ordernum']}'");
            $zymd=$arrdata[0]['year'].'-'.str_pad($arrdata[0]['month'],2,"0",STR_PAD_LEFT).'-'.str_pad($arrdata[0]['day'],2,'0',STR_PAD_LEFT);
            cookie('zymd',$zymd,604800);
            cookie('zhour',$arrdata[0]['hour'],604800);
            cookie('znickname',$arrdata[0]['username'],604800);
            cookie('zsex',$arrdata[0]['sex'],604800);

            $y=mb_substr(cookie('zymd'),0,4);//年
            $m=mb_substr(cookie('zymd'),5,2); //月
            $d=mb_substr(cookie('zymd'),8,2);//日
            $zyinli=yinli($y,$m,$d);
            cookie('zyangli',$y.'年'.$m.'月'.$d.'日'.' '.cookie('zhour').'时',604800);//阳历
            cookie('zyinli',$zyinli[0].'年'.$zyinli[1].$zyinli[2],604800);//阴历

            $zymd= cookie('zymd');
            cookie('orderid',$arrdata[0]['ordernum'],604800);
        }
        if(cookie('zsex')==1){
            $zsex='男';
        }else{
            $zsex='女';
        }
        if($zymd!=''){
            zwmp($zymd,cookie('zhour'),$zsex,'zw');
            $this->assign('shengxiao',I('globals.shengxiao'));//生肖
            $this->assign('sizhu',I('globals.sizhu'));//Z四柱
            $ssarray=array();
            array_push($ssarray,implode(I('globals.nianzhuss')));
            array_push($ssarray,implode(I('globals.yuezhuss')));
            array_push($ssarray,implode(I('globals.shizhuss')));
            $this->assign('nianzhuss',$ssarray);//十神
            $this->assign('canggan',I('globals.canggan'));//藏干

            $this->assign('zhishen',I('globals.zhishen'));//支神
            $this->assign('sizhuny',I('globals.sizhuny'));//四柱纳音
            $this->assign('bzdishi',I('globals.bzdishi'));//八字地势
            $this->assign('wxsqs',I('globals.wxsqs'));//旺相休囚死
            $this->assign('xiys',I('globals.xiys'));//喜用神
            $this->assign('taiyuan',I('globals.taiyuan'));//胎元
            $this->assign('rikong',I('globals.rikong'));//日空
            $this->assign('dayun',I('globals.dayun'));//大运
            $this->assign('dayunx',I('globals.dayunx'));//大运x
            $this->assign('dayuny',I('globals.dayuny'));//大运y
            $this->assign('dayungz',I('globals.dayungz'));//大运干支
            $this->assign('dayunss',I('globals.dayunss'));//大运十神
            hyqg(I('globals.srg'),I('globals.arrzx'),I('globals.arrtf'),I('globals.arrjix'),I('globals.arrxiongx'),I('globals.shua'));
            $this->assign('fqarrzhux',I('globals.fqarrzhux'));//婚姻主星状况
            hunyincesuan($zymd,I('globals.zhishen'));
            $this->assign('arrhycs',I('globals.arrhycs'));//桃花运势
            $this->assign('arrxiehou',I('globals.arrxiehou'));//邂逅年份
            $this->assign('dzssshuju',I('globals.dzssshuju'));//地址十神数据
            $this->assign('pofraction',I('globals.pofraction'));//配偶性格分数
            $this->assign('happiness',I('globals.happiness'));//幸福指数分数
            $this->assign('zhuwang',I('globals.zhuwang'));//助旺指数分数
            $this->assign('zinvfraction',I('globals.zinvfraction'));//子女运数分数
//            dump(I('globals.arrhycs'));
//            exit;
        }

        $this->assign('sex',cookie('zsex'));
        $this->display("Hycs/ZM_hunyincesuan_zhifu_jieguoye");
    }
    public function pay(){//支付宝支付

    }
    public function paywx(){//微信支付

    }

}